import Vue from 'vue'
import Vuex from 'vuex'
import * as actions from './actions'
import * as getters from './getters'

Vue.use(Vuex)

// 应用初始状态
const stateObj  = {
  count: 10,
  user: {
    user_name: "",
    user_id: "",
    user_type: ""

  },
  roles: [{
    role_id: '',
    role_name: ''
  }],
  tenants: [
    /* {
     resources: '',
     tenant_id: '',
     tenant_name: '',
     }*/
  ],
  datacenter: {
    center: {//当前选中的
      data_center_id: "",
      data_center_name: ""
    },
    list: [{
      data_center_id: "",
      data_center_name: ""
    }]
  },
  page6Sql: {
    data_hive_sql_id: '',
    sql_name: '',
    hive_database_name: '',
    sql_content: '',
  },
}
const state = JSON.parse(JSON.stringify(stateObj));

// 定义所需的 mutations
const mutations = {
  INCREMENT(state) {
    state.count++
  },
  DECREMENT(state) {
    state.count--
  },
  SETUSER(state, user){
    state.user.user_name = user.user_name || "";
    state.user.user_id = user.user_id || "";
    state.user.user_type = user.user_type || "";
  },
  SETDATACENTER(state, center){
    state.datacenter.center.data_center_id = center.data_center_id || "";
    state.datacenter.center.data_center_name = center.data_center_name || "";
  },
  SETDATACENTERLIST(state, list){
    state.datacenter.list = list;
  },
  SETROLES(state, roles){
    state.roles = roles;
  },
  SETTENANTS(state, tenants){
    state.tenants = tenants
  },
  SETPAGE6SQL(state, page6Sql){
    state.page6Sql = page6Sql;
  },
  RESETALL(state){
    state =  JSON.parse(JSON.stringify(stateObj))
  }
};

// 创建 store 实例
export default new Vuex.Store({
  actions,
  getters,
  state,
  mutations
})